package com.xiaoyu.izf.controller;

import com.xiaoyu.izf.aspect.RequestAuth;
import com.xiaoyu.izf.model.UserInfo;
import com.xiaoyu.izf.model.YqfMerchant;
import com.xiaoyu.izf.model.page.DataTableBean;
import com.xiaoyu.izf.model.page.ParamListBean;
import com.xiaoyu.izf.service.YqfStoreStatsService;
import com.xiaoyu.izf.util.DateTimeUtil;
import com.xiaoyu.izf.util.ParamUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/yqf_merchant_stats")
public class YqfMerchantStatsController extends BaseController {
    @Autowired
    private YqfStoreStatsService yqfStoreStatsService;

    @RequestMapping("/admin_list_page")
    @RequestAuth
    public String listPage(Model model) {
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        return "/mgr/yqf_stats/merchant_admin_list";
    }

    @RequestMapping("/admin_list")
    @ResponseBody
    @RequestAuth
    public DataTableBean list(HttpServletRequest request, @RequestBody String body) {
        UserInfo user = user(request);
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = yqfStoreStatsService.merchantForList(paramListBean,user);
        return dataTableBean;
    }

    @RequestMapping("/par_list_page")
    @RequestAuth
    public String parListPage(Model model) {
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        return "/mgr/yqf_stats/merchant_par_list";
    }

    @RequestMapping("/store_admin_list_page")
    @RequestAuth
    public String storeAdminlistPage(HttpServletRequest request,Model model) {
        String merchantId = ParamUtil.getString(request,"merchantId");
        UserInfo user = user(request);
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        List<YqfMerchant> merchants = yqfStoreStatsService.merchants(user);
        model.addAttribute("merchants",merchants);
        model.addAttribute("merchantId",merchantId);
        return "/mgr/yqf_stats/store_admin_list";
    }

    @RequestMapping("/store_admin_list")
    @ResponseBody
    @RequestAuth
    public DataTableBean storeAdminlist(HttpServletRequest request, @RequestBody String body) {
        UserInfo user = user(request);
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = yqfStoreStatsService.storeForList(paramListBean,user);
        return dataTableBean;
    }

    @RequestMapping("/store_day_admin_list_page")
    @RequestAuth
    public String storeDayAdminlistPage(HttpServletRequest request,Model model) {
        String storeId = ParamUtil.getString(request,"storeId");
        UserInfo user = user(request);
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        model.addAttribute("storeId",storeId);
        return "/mgr/yqf_stats/store_day_admin_list";
    }

    @RequestMapping("/store_day_admin_list")
    @ResponseBody
    @RequestAuth
    public DataTableBean storeDayAdminlist(HttpServletRequest request, @RequestBody String body) {
        UserInfo user = user(request);
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = yqfStoreStatsService.storeDaylist(paramListBean,user);
        return dataTableBean;
    }
}
